package com.ruoyi.common.cyzUtils;

import org.gavaghan.geodesy.Ellipsoid;
import org.gavaghan.geodesy.GeodeticCalculator;
import org.gavaghan.geodesy.GeodeticCurve;
import org.gavaghan.geodesy.GlobalCoordinates;

public class DistanceUtils {
    public static void main(String[] args){

//        传入纬度， 经度  计算距离
        GlobalCoordinates source = new GlobalCoordinates(28.11289, 120.98338);
        GlobalCoordinates target = new GlobalCoordinates(28.00708, 120.63768);

        double meter1 = getDistanceMeter(source, target, Ellipsoid.Sphere);
        double meter2 = getDistanceMeter(source, target, Ellipsoid.WGS84);

//        球面距离
        System.out.println("Sphere坐标系计算结果："+meter1 + "米");
//        gps
        System.out.println("WGS84坐标系计算结果："+meter2 + "米");
    }

    /**
     *
     * @param gpsFrom
     * @param gpsTo
     * @param ellipsoid
     * @return
     */
    public static double getDistanceMeter(GlobalCoordinates gpsFrom, GlobalCoordinates gpsTo, Ellipsoid ellipsoid){

        //创建GeodeticCalculator，调用计算方法，传入坐标系、经纬度用于计算距离
        GeodeticCurve geoCurve = new GeodeticCalculator().calculateGeodeticCurve(ellipsoid, gpsFrom, gpsTo);

        return geoCurve.getEllipsoidalDistance();
    }
}
